#include<bits/stdc++.h>
using namespace std;
const int N=200005;
inline int read(){
    int k=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        k=k*10+ch-'0';
        ch=getchar();
    }
    return k*f;
}
int t,n,a[N],c[N];
bool check(int m){
    for(int i=1;i<m;++i){
        if((a[i]-a[i-1])!=(a[i+1]-a[i])) return false;
    }
    return true;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=1;i<=n;++i){
            a[i]=read();
        }
        if(check(n)){
            printf("0");
            cout<<endl;
        }
    }
    return 0;
}

